import store from "../../store/store";
import $ from 'jquery'
import {url} from '../../util/config'
import {error, success} from "../../util/responseStatus";
import {message} from "antd";
import login from "../login";
function getNewLogin(values) {
    return updateModule(values)
}
export default function updateModule(values) {
    // moduleId
    // moduleType: folder-d or file-d
    // moduleUpdateName : 待修改名
    // moduleUpdateType: 待修改类型
    let status = null;
    console.log("values;",values)
    let newDate = {
        MODULE_ID: values.moduleId ,
        MODULE_PARENT_ID: values.moduleParentId,
        MODULE_NAME: values.moduleName,
        SORT_NUM: values.sortNum,
        MODULE_TYPE: values.moduleType,
        LAYOUT_TYPE: values.layoutType,
        LAYOUT_PARAMS: values.params,
        LAYOUT_AREA: values.layoutArea,
        MODULE_CONTENT: values.content
        // MODULE_DESC:values.desc
    }

    let token = localStorage.getItem("token")

    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
            'Authorization': token
        },
        method:"POST",
        contentType:"application/json",
        url: url.api_url+"Module/UpdateModule",
        data:JSON.stringify(newDate),
        success:function (result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                status = getNewLogin(values);
            }else {
                if(result.result=="ok"){
                    status = "ok"
                    message.success("修改成功");
                }else if(result.result=="exist"){
                    message.error("区域未统一")
                }else message.error("修改失败")
            }
        },
        error:function (error) {
            message.error("请求异常")
            status = "error"
        }
    })

    return status;
}
